/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.goods.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.goods.entity.ZtAddr;
import com.jeesite.modules.goods.entity.ZtOrder;
import com.jeesite.modules.goods.service.ZtAddrService;
import com.jeesite.modules.xcxAdmin.entity.ZtAdmin;

/**
 * 测试数据Controller
 * 
 * @author ThinkGem
 * @version 2018-04-22
 */
@Controller
@RequestMapping(value = "${adminPath}/ztAddr")
public class ZtAddrController extends BaseController {

	@Autowired
	private ZtAddrService ztAddrService;

	/**
	 * 获取数据
	 */
	@ModelAttribute
	public ZtAddr get(String id, boolean isNewRecord) {
		ZtAddr ztAddr=new ZtAddr();
		ztAddr.setId(id);
		return ztAddrService.get(ztAddr);
	}

	/**
	 * 查询列表
	 */
	@RequestMapping(value = { "list", "" })
	public String list(ZtAddr ztAddr, Model model,HttpSession session) {
		
		if(ztAddr!=null && ztAddr.getZtAdmin()!=null && StringUtils.isNotBlank(ztAddr.getZtAdmin().getId())){
			session.setAttribute("ztAddrAdminid", ztAddr.getZtAdmin().getId());
		}else{
			if(ztAddr==null){ztAddr=new ZtAddr();}
			ZtAdmin ztAdmin=new ZtAdmin();
			ztAdmin.setId(session.getAttribute("ztAddrAdminid").toString());
			ztAddr.setZtAdmin(ztAdmin);
		}
		
		model.addAttribute("ztAddr", ztAddr);
		
		
		return "modules/ztAddr/ztAddrList";
	}

	/**
	 * 查询列表数据
	 */
	
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<ZtAddr> listData(ZtAddr ztAddr, HttpServletRequest request,
			HttpServletResponse response,Model model,HttpSession session) {
		
		session.getAttribute("ztAdminId");
		
		Page<ZtAddr> page = ztAddrService.findPage(new Page<ZtAddr>(request,
				response), ztAddr);
		
		
		return page;
	}

	
}